﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using bdnt_pets_system.Tools;
using bdnt_pets_system.SystemServiceReference;
using bdnt_pets_system_Entity;
using bdnt_pets_system.Resources;

namespace bdnt_pets_system.PageViews.SystemViews
{
    public partial class RoleManagerControl : BaseUserControl
    {        
        SystemServiceReference.SystemServiceClient sysClient;
        public RoleManagerControl()
        {
            InitializeComponent();            
            sysClient = new SystemServiceReference.SystemServiceClient();
            InitEvent();
            QueryData();
        }

        void InitEvent()
        {
            sysClient.GetRoleObjListConditionCompleted += new EventHandler<GetRoleObjListConditionCompletedEventArgs>(sysClient_GetRoleObjListConditionCompleted);
            sysClient.DeleteRoleObjCompleted += new EventHandler<DeleteRoleObjCompletedEventArgs>(sysClient_DeleteRoleObjCompleted);
            btnSs.Click += new RoutedEventHandler(btnSs_Click);
            btnCs.Click += new RoutedEventHandler(btnCs_Click);
            btnNewObj.Click += new RoutedEventHandler(btnNewObj_Click);
        }

        void sysClient_DeleteRoleObjCompleted(object sender, DeleteRoleObjCompletedEventArgs e)
        {
            if (e.Result)
                QueryData();
        }

        void QueryData()
        {
            sysClient.GetRoleObjListConditionAsync(tbMc.Text);
        }

        void sysClient_GetRoleObjListConditionCompleted(object sender, GetRoleObjListConditionCompletedEventArgs e)
        {
            gdList.ItemsSource = e.Result;
        }

        void btnNewObj_Click(object sender, RoutedEventArgs e)
        {
            var cupage = new NewRoleControl();
            App.ToPage(cupage);//跳转页面
        }

        void btnCs_Click(object sender, RoutedEventArgs e)
        {
            tbMc.Text = "";
        }

        void btnSs_Click(object sender, RoutedEventArgs e)
        {
            QueryData();
        }      
         
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {            
            sysClient.CloseAsync();
            var cuObj = (sender as HyperlinkButton).Tag as Tbl_Role;
            var cupage = new NewRoleControl(cuObj.Id);
            App.ToPage(cupage);//跳转页面
        }

        private void HyperlinkButton_Click_1(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(MyStrings.qdyscm,MyStrings.ts, MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                return;
            var cuObj = (sender as HyperlinkButton).Tag as Tbl_Role;
            sysClient.DeleteRoleObjAsync(cuObj.Id);
        }
    }
}
